package com.example.test.repository;

import com.example.test.mapper.UserMapper;
import com.example.test.model.Order;
import com.example.test.model.User;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Primary
public class MyBatisUserRepository implements UserRepository {
    private final UserMapper userMapper;

    public MyBatisUserRepository(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @Override
    public void save(User user) {
        userMapper.save(user);
    }

    @Override
    public User findById(long id) {
        return userMapper.findById(id);
    }

    @Override
    public List<User> find(int offset, int limit) {
        return userMapper.find(offset, limit);
    }

    @Override
    public List<Order> findRecentOrdersByUserId(long userId) {
        return userMapper.findRecentOrdersByUserId(userId);
    }

    @Override
    public void update(User user) {
        userMapper.update(user);
    }

    @Override
    public void deleteById(long id) {
        userMapper.deleteById(id);
    }
}
